package cc.ding.service.Impl;

import cc.ding.dao.Impl.PunchClockDaoImpl;
import cc.ding.dao.PunchClockDao;
import cc.ding.service.PunchClockService;

import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

public class PunchClockServiceImpl implements PunchClockService {

    PunchClockDao punchClockDao = new PunchClockDaoImpl();
    @Override
    public Map<String, String> punchClock(Integer empId) {
        String msg = "";
        //判断今天是否有考勤记录
        int i = punchClockDao.todayPunching(empId);
        if (i==0){
            //创建考勤记录

            punchClockDao.createPunching(empId);
        }


        //规则 ：打卡     01:00~12:00 上班卡   13:00~23:00
        //判断今天是否有考勤记录
        LocalTime sbStartTime = LocalTime.of(1,0); //1:00 AM
        LocalTime sbEndTime = LocalTime.of(12,0);  //12:00 AM

        LocalTime xbStartTime = LocalTime.of(13,0); //13:00 PM
        LocalTime xbEndTime = LocalTime.of(23,0);  //23:00 PM
        //获取当前时间
        LocalTime now = LocalTime.now();

        if (now.isAfter(sbStartTime) && now.isBefore(sbEndTime)){
            System.out.println("进行上班打卡");
            punchClockDao.updateStartTime(empId);
            msg = "上班打卡成功！，冲冲冲！";
        }
        if (now.isAfter(xbStartTime) && now.isBefore(xbEndTime)){
            System.out.println("进行下班打卡");
            punchClockDao.updateEndTime(empId);
            msg = "下班打卡成功！，下班愉快！";
        }
        Map<String ,String> map = new HashMap<>();
        map.put("msg",msg);

        return map;
    }
}
